'abutoolbox.monkey by Belimoth
Strict

Private

Global hexChars:String[] = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]

Public

Function PaddedDecToHex:String(dec:Int, pad:Int = -1)
	Local hex:String = ""
	If dec <= 0
		If pad = -1
			Return "0"
		Else
			Return PadLeft("0", pad, "0")
		Endif
	Endif
	While dec > 0
		hex += hexChars[ (dec Mod 16) ]
		dec = dec / 16
	Wend
	If pad = -1
		Return hex
	Else
		Return PadLeft(hex, pad, "0")
	Endif
End

Function PadLeft:String(str:String, len:Int, char:String = " ")
	While str.Length() < len
		str = char + str
	Wend
	Return str
End

Function Xor:Bool(a:Bool, b:Bool)		'untested
	Return (a Or b) And Not (a And b)
End

Function FillBoolArray:Bool[](length:Int, value:bool)		'untested
	Local arr:Bool[] = New Bool[length]
	For Local n:= 0 Until length
		arr[n] = value
	Next
	Return arr
End

Function FillIntArray:Int[](length:Int, value:Int)		'untested
	Local arr:Int[] = New Int[length]
	For Local n:= 0 Until length
		arr[n] = value
	Next
	Return arr
End

Function ConcantenateIntArrays:Int[] (a:Int[], b:Int[])		'untested
	a = a.Resize(a.Length + b.Length)
	For Local n := 0 Until b.Length
		a[a.Length - n - 1] = b[b.Length - n - 1]
	Next
	Return a
End